package com.qr.cch.it.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qr.cch.it.entity.Admin;
import com.qr.cch.it.entity.Result;
import com.qr.cch.it.entity.StatusCode;
import com.qr.cch.it.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 描述:
 *
 * @author chenconghua
 * @version 1.0
 * @create 2022-10-01 11:46 PM
 */
@CrossOrigin
@RestController
@RequestMapping("/admin")
public class AdminController  {

    @Autowired
    private AdminService adminService;


    @GetMapping("list")
    public Result list(){

        return new Result(true, StatusCode.OK,"cc",adminService.list());
    }

    @PostMapping("login")
    public Result login(@RequestBody Map m){

        String username= (String) m.get("username");
        String password= (String) m.get("password");

        QueryWrapper<Admin> queryWrapper =new QueryWrapper();
        queryWrapper.eq("username",username);

        if(null!=adminService.getOne(queryWrapper)){

            Admin admin = adminService.getOne(queryWrapper);
            if (admin.getPassword().equals(password)){
                return new Result(true , StatusCode.OK,"登陆成功",admin);
            }else{
                return new Result(false , StatusCode.ERROR,"密码错误");
            }
        }else{
            return new Result(false , StatusCode.ERROR,"用户名错误");
        }
    }
}
